package cn.iocoder.yudao.module.member.dal.mysql.pickupinfo;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.app.pickupinfo.vo.PickupInfoPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.pickupinfo.PickupInfoDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 用户提料人信息 Mapper
 *
 * @author admin
 */
@Mapper
public interface PickupInfoMapper extends BaseMapperX<PickupInfoDO> {

    default PageResult<PickupInfoDO> selectPage(PickupInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PickupInfoDO>()
                .eqIfPresent(PickupInfoDO::getUserId, reqVO.getUserId())
                .likeIfPresent(PickupInfoDO::getName, reqVO.getName())
                .eqIfPresent(PickupInfoDO::getMobile, reqVO.getMobile())
                .eqIfPresent(PickupInfoDO::getIdNo, reqVO.getIdNo())
                .eqIfPresent(PickupInfoDO::getIdCardPic, reqVO.getIdCardPic())
                .eqIfPresent(PickupInfoDO::getDefaultStatus, reqVO.getDefaultStatus())
                .betweenIfPresent(PickupInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PickupInfoDO::getId));
    }

    default List<PickupInfoDO> selectListByUserIdAndDefaulted(Long userId, Boolean defaulted) {
        return selectList(new LambdaQueryWrapperX<PickupInfoDO>()
                .eq(PickupInfoDO::getUserId, userId)
                .eqIfPresent(PickupInfoDO::getDefaultStatus, defaulted));
    }

    default long selectCountByUserAndIdNo(Long userId, String idNo) {
        return selectCount(new LambdaQueryWrapperX<PickupInfoDO>().eq(PickupInfoDO::getUserId, userId)
                .eqIfPresent(PickupInfoDO::getIdNo,idNo));
    }
}